The present invention relates generally to a computer implemented method for debugging and analyzing code executing on a processor. More specifically, the present invention relates to tracking objects and their references to be able to understand what happens with the dynamic memory heap.
Most of the programming languages/run time systems support dynamic memory allocation and reclamation. In object-oriented languages, memory can be reserved and released on a per-object basis, for example, through object allocation and reclamation. In some languages, for example, C++, freeing memory occupied by an object is done explicitly, by calling a special system function. In other object-oriented languages, for example, Java, that support so-called automatic memory management, memory occupied by objects that are not in use anymore is reclaimed automatically by a run time subsystem called a garbage collector. In Java, an object is considered unused and available for reclamation if it is not reachable directly or indirectly from any object graph root. The heap roots can include the set of system classes, Java Native Interface (JNI) globals, references from thread stacks, and other objects used as roots for the purposes of garbage collection. A heap is the area of memory where allocations of memory to objects occur on a dynamic basis.
A memory leak in a program written in a language such as C++, with manual memory management, is a well-known problem that happens when a program does not explicitly free some objects or memory area that is previously reserved. During program execution, allocations without reclamation may repeat over and over again. Accordingly, these allocations may ultimately exhaust all the available memory, thereby causing the program to crash.
In the past, software developers and analysts used Java™ Virtual Machine Profiler Interface (JVMPI) to get various profiling data from the Java Virtual Machine (JVM). Java is a trademark of Sun Microsystems, Inc. For heap profiling, JVMPI has several shortcomings. First, during heap dump (a snapshot of the current heap state), JVMPI creates a shadow copy of the heap, thus doubling the memory requirements. For very large heap sizes, heap dump is not feasible. Moreover, garbage collection is completely suspended during the JVMPI event that notifies a profiler about an object allocation. To identify an object, JVMPI uses an opaque pointer representing an object ID. Starting with the Java version 5.0, JVMPI is deprecated in the favor of new Java Virtual Machine Tool Interface (JVMTI).
As a response to anomalous memory allocation, as well as for other purposes, software developers use Java Virtual Machine Tool Interface (JVMTI) so they may develop debugging, profiling, and monitoring tools for Java™ Virtual Machines or JVMs. For example, JVMTI allows software developers to create software agents that monitor Java programming language applications. An agent registers to be notified about an event of interest by setting a callback function for that event and enabling the event, via calls to the corresponding JVMTI functions. The JVMTI set of functions and events can be extended in the manner described in Java™ Platform Profiling Architecture© 2004, Sun Microsystems, Inc. Accordingly, new functions and events can be added to the JVMTI.
JVMTI allows a user to attach a tag of type jlong (a 64 bit value) or object tag, to any Java object in the heap. This object tag is continually associated with the Java object, including movements caused by compaction after Garbage Collection (GC). The object tag can be user-supplied, using the JVMTI SetTag function. The object tag can be a mnemonic or other identifier so that an object tag is identifiable with tools that analyze the heap. Accordingly, the JVMTI Heap Iterate function can provide these tag values as a form of object identification when the developer invokes the heap iterate function to reveal the status of active or live objects within the data processing system.
All objects, features, and advantages of the present invention will become apparent in the following detailed written description.